#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>

using namespace std;

vector<int> getGoodIndices(vector<vector<int>>& variables, int target) {
    vector<int> res;
    for (int i = 0; i < variables.size(); i++)
        if (qmi(qmi(variables[i][0], variables[i][1], 10), variables[i][2], variables[i][3]) == target)
            res.push_back(i);
    return res;
}

int qmi(int a, int b, int m)
{
    int res = 1;
    while (b)
    {
        if (b & 1)   res = (res * a) % m;
        a = (a * a) % m;
        b >>= 1;
    }
    return res;
}